package me.jessyan.mvparms.demo.mvp.ui.activity.auth;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DoubleClickUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.di.component.auth.DaggerHasAndNoAuthComponent;
import me.jessyan.mvparms.demo.di.module.auth.HasAndNoAuthModule;
import me.jessyan.mvparms.demo.mvp.contract.auth.HasAndNoAuthContract;
import me.jessyan.mvparms.demo.mvp.presenter.auth.HasAndNoAuthPresenter;
import me.jessyan.mvparms.demo.mvp.ui.widget.CustomToolbar;
import me.jessyan.mvparms.demo.mvp.ui.widget.PercentLinearLayout;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * 没有实名认证 和已经实名
 */
public class HasAndNoAuthActivity extends BaseActivity<HasAndNoAuthPresenter> implements HasAndNoAuthContract.View {
    boolean hasAuth = false;
    @BindView(R.id.toolbar)
    CustomToolbar toolbar;
    @BindView(R.id.auth_tv)
    TextView authTv;
    @BindView(R.id.restart_tv)
    TextView restartTv;
    @BindView(R.id.auth_ll)
    PercentLinearLayout authLl;
    @BindView(R.id.on_auth_ll)
    View noAuthLl;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {

        DaggerHasAndNoAuthComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .hasAndNoAuthModule(new HasAndNoAuthModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_has_and_no_auth; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    /**
     * 当启动模式为singletop的，第二次打开这个activity的时候，就不再onCreate（），而是走onNewIntent（），这样才能获取到新的数据
     * @param intent
     */
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        //必须设置新的intent
        setIntent(intent);

        upDateHasAuth(intent.getBooleanExtra("type",false));

    }


    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        toolbar.setListener(new CustomToolbar.ToolbarListener() {
            @Override
            public void onLeftBack() {
                finish();
            }

            @Override
            public void onRightBack() {

            }
        });
        upDateHasAuth(getIntent().getBooleanExtra("type",false));
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }



    @OnClick({R.id.auth_tv ,R.id.restart_tv})
    public void onViewClicked(View view) {
        if (DoubleClickUtils.getInstance().isDouble(view)) {
            return;
        }
        switch (view.getId()) {
            case R.id.auth_tv:
                startActivity(new Intent(HasAndNoAuthActivity.this, AuthActivity.class));
                break;
            case R.id.restart_tv:
                startActivity(new Intent(HasAndNoAuthActivity.this, AuthActivity.class));
                break;
            default:
        }
    }

    @Override
    public void upDateHasAuth(boolean hasHasAuth) {
        this.hasAuth = hasHasAuth;
        if (hasHasAuth){
            authLl.setVisibility(View.VISIBLE);
            noAuthLl.setVisibility(View.GONE);
        }else {
            noAuthLl.setVisibility(View.VISIBLE);
            authLl.setVisibility(View.GONE);
        }
    }


}
